<?php
namespace app\admin\controller;
use think\Controller;

class Login extends Controller
{
    public function index()
    {
    	if (cookie('user')) {
    		$this->redirect("/index.php/Admin/Index/index");
    		return;
    	}
        return $this->fetch();
    }

    // 用户登录
    public function login() {
    	$map = array(
    		'user' => $_POST['user'],
    		'password' => md5($_POST['password'])
    	);
    	$admin = model("Admin");
    	if ($admin->where($map)->find()) {
    		cookie('user', $_POST['user'], 3600);
    		$this->success("登录成功", '/index.php/Admin/Index/index');
    	} else {
    		$this->error("登录失败", '/index.php/Admin/Login');
    	}
    }
}
